#define  _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>

using namespace std;
//最大子数组和
//动态规划问题
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        //创建dp表
        vector<int> dp(n + 1);
        //初始化
        dp[0] = 0;
        //填表
        for (int i = 1; i <= n; i++)
        {
            dp[i] = max(nums[i - 1], dp[i - 1] + nums[i - 1]);
        }
        //返回值
        int ret = INT_MIN;
        for (int i = 1; i <= n; i++)
        {
            ret = max(ret, dp[i]);
        }
        return ret;

    }
};
//可以简化一下在一次循环中就完成最大值的更新
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        //创建dp表
        vector<int> dp(n + 1);

        //初始化
        int ret = INT_MIN;
        dp[0] = 0;
        //填表
        for (int i = 1; i <= n; i++)
        {
            dp[i] = max(nums[i - 1], dp[i - 1] + nums[i - 1]);
            ret = max(ret, dp[i]);
        }
        //返回值
        return ret;

    }
};

int main()
{

	return 0;
}